package cn.tedu.sso.controller;

import cn.tedu.base.response.JsonResult;
import cn.tedu.sso.pojo.po.LoginByCodeRequest;
import cn.tedu.sso.pojo.po.LoginRequest;
import cn.tedu.sso.service.SSOService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/font/sso")
@Api("登录模块")
public class SsoController {



    @Autowired
    private SSOService ssoService;

    @ApiOperation(value = "密码登录功能")
    @PostMapping("login")
    public JsonResult login(@RequestBody LoginRequest loginRequest, HttpServletRequest request){
        log.debug("用户登录信息：loginRequest:{}",loginRequest);
        //通过ssoService的login方法来获取用户的token
        return ssoService.login(loginRequest, request);
    }

    @GetMapping("getCode")
    public JsonResult login(@RequestParam String phoneNum){
        ssoService.verificationCode(phoneNum);
        return JsonResult.ok();
    }

    @ApiOperation(value = "验证码登录功能")
    @PostMapping("loginByCode")
    public JsonResult loginByCode(@RequestBody LoginByCodeRequest loginByCodeRequest){
        log.debug("loginByCodeRequest:{}",loginByCodeRequest);
        return ssoService.loginByCode(loginByCodeRequest);
    }

    @GetMapping("loginContinue")
    public JsonResult loginContinue() throws IOException {
        return ssoService.loginContinue();
    }

    @GetMapping("/outLogin/{userId}")
    public JsonResult outLogin(@PathVariable Long userId) {
        log.debug("userId:{}",userId);
        return ssoService.outLogin(userId);
    }
}
